home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2004 April / SGI IRIX 6.5 Applications 2004 April.iso / dist / mozilla.idb / var / netscape / mozilla / chrome / comm.jar.z / comm.jar / content / cookie / cookieAcceptDialog.js < prev    next >
Text File  |  2003-11-11  |  9KB  |  202 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  4.  * The contents of this file are subject to the Mozilla Public License Version
  5.  * 1.1 (the "License"); you may not use this file except in compliance with
  6.  * the License. You may obtain a copy of the License at
  7.  * http://www.mozilla.org/MPL/
  8.  *
  9.  * Software distributed under the License is distributed on an "AS IS" basis,
  10.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11.  * for the specific language governing rights and limitations under the
  12.  * License.
  13.  *
  14.  * The Original Code is cookie manager code.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * Michiel van Leeuwen.
  18.  * Portions created by the Initial Developer are Copyright (C) 2002
  19.  * the Initial Developer. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *
  23.  * Alternatively, the contents of this file may be used under the terms of
  24.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  25.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26.  * in which case the provisions of the GPL or the LGPL are applicable instead
  27.  * of those above. If you wish to allow use of your version of this file only
  28.  * under the terms of either the GPL or the LGPL, and not to allow others to
  29.  * use your version of this file under the terms of the MPL, indicate your
  30.  * decision by deleting the provisions above and replace them with the notice
  31.  * and other provisions required by the GPL or the LGPL. If you do not delete
  32.  * the provisions above, a recipient may use your version of this file under
  33.  * the terms of any one of the MPL, the GPL or the LGPL.
  34.  *
  35.  * ***** END LICENSE BLOCK ***** */
  36.  
  37. const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
  38. const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
  39. const nsICookie = Components.interfaces.nsICookie;
  40.  
  41. var params; 
  42. var cookieBundle;
  43. var gDateService = null;
  44.  
  45. var showDetails = "";
  46. var showDetailsAccessKey = "";
  47. var hideDetails = "";
  48. var hideDetailsAccessKey = "";
  49.  
  50. function onload()
  51. {
  52.   doSetOKCancel(cookieAccept, cookieDeny);
  53.  
  54.   var dialog = document.documentElement;
  55.  
  56.   document.getElementById("ok").label = dialog.getAttribute("acceptLabel");
  57.   document.getElementById("cancel").label = dialog.getAttribute("cancelLabel");
  58.  
  59.   if (!gDateService) {
  60.     const nsScriptableDateFormat_CONTRACTID = "@mozilla.org/intl/scriptabledateformat;1";
  61.     const nsIScriptableDateFormat = Components.interfaces.nsIScriptableDateFormat;
  62.     gDateService = Components.classes[nsScriptableDateFormat_CONTRACTID]
  63.                              .getService(nsIScriptableDateFormat);
  64.   }
  65.  
  66.   cookieBundle = document.getElementById("cookieBundle");
  67.  
  68.   //cache strings
  69.   if (!showDetails) {
  70.     showDetails = cookieBundle.getString('showDetails');
  71.     showDetailsAccessKey = cookieBundle.getString('showDetailsAccessKey');
  72.   }
  73.   if (!hideDetails) {
  74.     hideDetails = cookieBundle.getString('hideDetails');
  75.     hideDetailsAccessKey = cookieBundle.getString('hideDetailsAccessKey');
  76.   }
  77.  
  78.   if (document.getElementById('infobox').hidden) {
  79.     document.getElementById('disclosureButton').setAttribute("label",showDetails);
  80.     document.getElementById('disclosureButton').setAttribute("accesskey",showDetailsAccessKey);
  81.   } else {
  82.     document.getElementById('disclosureButton').setAttribute("label",hideDetails);
  83.     document.getElementById('disclosureButton').setAttribute("accesskey",hideDetailsAccessKey);
  84.   }
  85.  
  86.   if ("arguments" in window && window.arguments.length >= 1 && window.arguments[0]) {
  87.     try {
  88.       params = window.arguments[0].QueryInterface(nsIDialogParamBlock);
  89.       var objects = params.objects;
  90.       var cookie = params.objects.queryElementAt(0,nsICookie);
  91.       
  92.       var cookiesFromHost = params.GetInt(nsICookieAcceptDialog.COOKIESFROMHOST);
  93.  
  94.       var messageFormat;
  95.       if (params.GetInt(nsICookieAcceptDialog.CHANGINGCOOKIE))
  96.         messageFormat = 'permissionToModifyCookie';
  97.       else if (cookiesFromHost > 1)
  98.         messageFormat = 'permissionToSetAnotherCookie';
  99.       else if (cookiesFromHost == 1)
  100.         messageFormat = 'permissionToSetSecondCookie';
  101.       else
  102.         messageFormat = 'permissionToSetACookie';
  103.  
  104.       var hostname = params.GetString(nsICookieAcceptDialog.HOSTNAME);
  105.  
  106.       var messageText;
  107.       if (cookie)
  108.         messageText = cookieBundle.getFormattedString(messageFormat,[hostname, cookiesFromHost]);
  109.       else
  110.         // No cookies means something went wrong. Bring up the dialog anyway
  111.         // to not make the mess worse.
  112.         messageText = cookieBundle.getFormattedString(messageFormat,["",cookiesFromHost]);
  113.  
  114.       var messageParent = document.getElementById("dialogtextbox");
  115.       var messageParagraphs = messageText.split("\n");
  116.  
  117.       // use value for the header, so it doesn't wrap.
  118.       var headerNode = document.getElementById("dialog-header");
  119.       headerNode.setAttribute("value",messageParagraphs[0]);
  120.  
  121.       // use childnodes here, the text can wrap
  122.       for (var i = 1; i < messageParagraphs.length; i++) {
  123.         var descriptionNode = document.createElement("description");
  124.         text = document.createTextNode(messageParagraphs[i]);
  125.         descriptionNode.appendChild(text);
  126.         messageParent.appendChild(descriptionNode);
  127.       }
  128.  
  129.       if (cookie) {
  130.         document.getElementById('ifl_name').setAttribute("value",cookie.name);
  131.         document.getElementById('ifl_value').setAttribute("value",cookie.value);
  132.         document.getElementById('ifl_host').setAttribute("value",cookie.host);
  133.         document.getElementById('ifl_path').setAttribute("value",cookie.path);
  134.         document.getElementById('ifl_isSecure').setAttribute("value",
  135.                                                                  cookie.isSecure ?
  136.                                                                     cookieBundle.getString("yes") : cookieBundle.getString("no")
  137.                                                           );
  138.         document.getElementById('ifl_expires').setAttribute("value",GetExpiresString(cookie.expires));
  139.         document.getElementById('ifl_isDomain').setAttribute("value",
  140.                                                                  cookie.isDomain ?
  141.                                                                     cookieBundle.getString("domainColon") : cookieBundle.getString("hostColon")
  142.                                                             );
  143.       }
  144.       // set default result to not accept the cookie
  145.       params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
  146.       // and to not persist
  147.       params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, 0);
  148.     } catch (e) {
  149.     }
  150.   }
  151. }
  152.  
  153. function showhideinfo()
  154. {
  155.   var infobox=document.getElementById('infobox');
  156.  
  157.   if (infobox.hidden) {
  158.     infobox.setAttribute("hidden","false");
  159.     document.getElementById('disclosureButton').setAttribute("label",hideDetails);
  160.     document.getElementById('disclosureButton').setAttribute("accesskey",hideDetailsAccessKey);
  161.   } else {
  162.     infobox.setAttribute("hidden","true");
  163.     document.getElementById('disclosureButton').setAttribute("label",showDetails);
  164.     document.getElementById('disclosureButton').setAttribute("accesskey",showDetailsAccessKey);
  165.   }
  166.   sizeToContent();
  167. }
  168.  
  169. function cookieAccept()
  170. {
  171.   // say that the cookie was accepted
  172.   params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 1); 
  173.   // And remember that when needed
  174.   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
  175.   window.close();
  176. }
  177.  
  178. function cookieDeny()
  179. {
  180.   // say that the cookie was rejected
  181.   params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0); 
  182.   // And remember that when needed
  183.   params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
  184.   window.close();
  185. }
  186.  
  187. function GetExpiresString(secondsUntilExpires) {
  188.   if (secondsUntilExpires) {
  189.     var expireDate = new Date(1000*secondsUntilExpires);
  190.     return gDateService.FormatDateTime("", gDateService.dateFormatLong,
  191.                                        gDateService.timeFormatSeconds, 
  192.                                        expireDate.getFullYear(),
  193.                                        expireDate.getMonth()+1, 
  194.                                        expireDate.getDate(), 
  195.                                        expireDate.getHours(),
  196.                                        expireDate.getMinutes(), 
  197.                                        expireDate.getSeconds());
  198.   }
  199.   return cookieBundle.getString("atEndOfSession");
  200. }
  201.  
  202.